package jianzhi_offer;

public class _10_二进制中1的个数 {
	public static void main(String[] args) {
		_10_二进制中1的个数 test = new _10_二进制中1的个数();
		System.out.println(test.NumberOf1_(8888));
		System.out.println(test.NumberOf1(8888));
	}
	
	public int NumberOf1(int n) {
		return Integer.bitCount(n);
    }
	
	public int NumberOf1_(int n) {
		int res = 0,i = 0;
		while(i < 32) {
			if(((n>>i) & 1) ==1) {
				++res;
			}
			i++;
		}
		return res;
    }
}
